﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ZHDJ.Data.Models.MassLine
{
    public class PartyMassLineSuggest : EntityBase
    {
        #region 字段属性
        /// <summary>
        /// 标题
        /// </summary>
        public string Title { get; set; }

        /// <summary>
        /// 用户id
        /// </summary>
        public string LoginID { get; set; }

        /// <summary>
        /// 用户名
        /// </summary>
        public string UserName { get; set; }

        /// <summary>
        /// 所属组织
        /// </summary>
        public string BranchID { get; set; }

        /// <summary>
        /// 内容
        /// </summary>
        public string Content { get; set; }

        /// <summary>
        /// 联系方式
        /// </summary>
        public string ContactWay { get; set; }

        /// <summary>
        /// 联系地址
        /// </summary>
        public string Address { get; set; }

        /// <summary>
        /// 状态  0：未回复   1：已经回复 
        /// </summary>
        public bool? Statue { get; set; }

        /// <summary>
        /// 回复内容
        /// </summary>
        public string Reply { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime? CreateTime { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public string ModifyBy { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public DateTime? ModifyTime { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public bool? ShowInHomePage { get; set; }

        #endregion

        #region 查询管理

        /// <summary>
        /// 获取GetDataGrid数据源
        /// </summary>
        /// <returns></returns>
        public static DataSet GetGridData(int pageIndex, int pageSize, string title, string createBy, string statue)
        {
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter()
                {
                    DbType = DbType.Int32,
                    ParameterName = "Begin",
                    Value = (pageIndex)*pageSize
                },
                new MySqlParameter()
                {
                    DbType = DbType.Int32,
                    ParameterName = "PageSize",
                    Value = pageSize
                }
            };
            StringBuilder sbSql = new StringBuilder();
            sbSql.Append(@"SELECT SQL_CALC_FOUND_ROWS ID, Title, data.UserName, data.ContactWay,data.Address, data.CreateTime, data.ModifyTime, data.Reply,
IF(Statue=1,'已回复','待回复') as StatusName,IF(ShowInHomePage=1,'是','否') as ShowInHomePage
                                FROM tblPartyMassLineSuggest data  
                                Where 1=1 ");
            if (!string.IsNullOrEmpty(title))
            {
                sbSql.AppendFormat(" and title like '%{0}%'", title);
            }
            if (!string.IsNullOrEmpty(createBy))
            {
                sbSql.AppendFormat(" and UserName like '%{0}%'", createBy);
            }
            if (!string.IsNullOrEmpty(statue))
            {
                sbSql.AppendFormat(" and statue='{0}'", statue);
            }
            sbSql.Append(" order by CreateTime desc  LIMIT ?Begin ,?PageSize;SELECT FOUND_ROWS()");

            return MySqlHelper.ExecuteDataSet(sbSql.ToString(), parameters.ToArray());
        }
    }
    #endregion
}